<html xmlns:th="http://www.thymeleaf.org">
<head>
    <!--资源获取-->
    <base th:href="|${#request.getContextPath()}/|">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="static/lib/html5shiv.js"></script>
    <script type="text/javascript" src="static/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="static/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="static/lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!--layui-->
    <link rel="stylesheet" type="text/css" href="static/layui/css/layui.css"/>
    <style>
        .layui-form-checkbox span {
            height: 20px;
        }

    </style>
    <script type="text/javascript" src="static/layui/layui.js"></script>
    <title>资讯列表</title>
</head>
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i>
    首页
    <span class="c-gray en">&gt;</span>
    记账本
    <span class="c-gray en">&gt;</span>
    添加种类
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
       href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">输入标题</label>
        <div class="layui-input-block">
            <input type="hidden" id="classId" th:value="${class.classId}">
            <input type="text" id="className" name="title" required  lay-verify="required" th:value="${class.className}" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea id="classRemark" name="desc" th:value="${class.classRemark}" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开启周期</label>
            <div class="layui-input-block">
                <input id="checkbox"  lay-filter="switchTest" type="checkbox" name="switch" lay-skin="switch">
            </div>
        </div>

        <div id="divhide" >
            <div class="layui-form-item  ">
                <label class="layui-form-label">金额</label>
                <div class="layui-input-block">
                    <input id="classMoney" type="text" name="title" lay-verify="number" th:value="${class.classMoney}"  placeholder="请输入金额" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-fluid">
                <div class="layui-card">
                    <div class="layui-card-header">周期设置</div>
                    <div class="layui-card-body">
                        <input id="cron"  class="layui-input" th:value="${class.classZq}"/>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="static/lib/jquery/1.9.1/jquery.min.js"></script>

<script type="text/javascript" src="static/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/lib/laypage/1.2/laypage.js"></script>

<script>
    var cronStrs = "";
    function divhide(hidedivvar){
        if(hidedivvar != null){
            $("#divhide").removeClass("layui-hide");
            $("#checkbox").val(false);
        }else {
            $("#divhide").addClass("layui-hide");
            $("#checkbox").val(true);
        }
    }
    divhide('[[${class.classZq}]]');

    layui.config({base: "static/layui_exts/"}).extend({cron: "cron/cron",}).use(["cron"], function() {
            var $ = layui.$,
                cron = layui.cron;
            cron.render({
                elem: "#cron", // 绑定元素
                done: function(cronStr) {
                    cronStrs = cronStr;
                },
            });
    });
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        var classId=$("#classId").val();
        var userId=[[${session.session_user.uId}]];
        var className=$("#className").val();
        var classRemark=$("#classRemark").val();
        var classZq=cronStrs;
        var classMoney=$("#classMoney").val();
        //监听提交
        form.on('submit(formDemo)', function(data){
            console.log(data);
            $.ajax({
                url:"acc/xgAcc",
                type:"POST",
                data:{
                    "classId":$("#classId").val(),
                    "userId":[[${session.session_user.uId}]],
                    "className":$("#className").val(),
                    "classRemark":$("#classRemark").val(),
                    "classZq":cronStrs,
                    "classMoney":$("#classMoney").val()
                },success:function () {
                    console.log("成功")
                }
            })
            return false;
        });
        form.on('switch(switchTest)', function (data) {
            if(data.elem.checked){
                $("#divhide").removeClass("layui-hide");

            }else {
                $("#divhide").addClass("layui-hide");
            }
        });
    });
</script>
</body>
</html>
